package com.qf.business.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.business.goods.mapper.GoodsFenleiGuigeMapper;
import com.qf.business.goods.service.GoodsFenleiGuigeService;
import com.qf.data.goods.entity.GoodsFenleiGuige;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (GoodsFenleiGuige)表服务实现类
 *
 * @author makejava
 * @since 2022-07-05 10:20:38
 */
@Service
public class GoodsFenleiGuigeServiceImpl extends ServiceImpl<GoodsFenleiGuigeMapper, GoodsFenleiGuige> implements GoodsFenleiGuigeService {

    @Autowired
    private GoodsFenleiGuigeMapper goodsFenleiGuigeMapper;

    /**
     * 修改指定分类的规格列表
     * @param fenleiId
     * @param guigeIds
     * @return
     */
    @Override
    public int updateFenleiGuige(Long fenleiId, String[] guigeIds) {

        //1、根据分类删除 管理的 规格记录
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("fenlei_id", fenleiId);
        goodsFenleiGuigeMapper.delete(queryWrapper);

        //2、设置分类下的规格
        if (guigeIds != null || guigeIds.length > 0) {
            for (String guigeId : guigeIds) {
                GoodsFenleiGuige fenleiGuige = new GoodsFenleiGuige();
                fenleiGuige.setFenleiId(fenleiId);
                fenleiGuige.setGuigeId(Long.parseLong(guigeId));
                //保存
                goodsFenleiGuigeMapper.insert(fenleiGuige);
            }
        }

        return 1;
    }
}


